package com.sfzy.controller;

import com.sfzy.service.CompanyInfoService;
import com.sfzy.entity.CompanyInfo;
import com.sfzy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("companyInfo")
public class CompanyInfoController {
    @Autowired
    CompanyInfoService companyInfoService;

    @PostMapping
    public R addCompanyInfo(@RequestBody CompanyInfo companyInfo) {
        return R.ok(companyInfoService.addCompanyInfo(companyInfo));
    }

    @PutMapping
    public R updateCompanyInfo(@RequestBody CompanyInfo companyInfo) {
        return R.ok(companyInfoService.updateCompanyInfo(companyInfo));
    }

    @DeleteMapping("{id}")
    public R deleteCompanyInfo(@PathVariable("id") int id) {
        return R.ok(companyInfoService.deleteCompanyInfoById(id));
    }

    @GetMapping("{id}")
    public R getCompanyInfo(@PathVariable("id") int id) {
        return R.ok(companyInfoService.getCompanyInfoById(id));
    }

    @GetMapping("page")
    public R getCompanyInfoPage(CompanyInfo companyInfo,
                                @RequestParam(defaultValue = "1",required = false) int pageNum,
                                @RequestParam(defaultValue = "6",required = false) int pageSize) {
        return R.ok(companyInfoService.getCompanyInfoByPage(companyInfo, pageNum, pageSize));
    }
}
